package com.lm.scau.dyb.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lm.scau.dyb.R;
import com.lm.scau.dyb.activity.base.BaseActivity;
import com.lm.scau.dyb.utils.FlagHelper;

import java.util.List;
import java.util.Map;
import java.util.zip.Inflater;

/**
 * Function:
 * auth：liming on 2016/8/15 11:32
 * mail：liming@wxchina.com
 */
public class UserItemAdapter extends BaseAdapter {
    private BaseActivity activity;
    private List<Map<String, Object>> list;

    public UserItemAdapter(BaseActivity activity, List<Map<String, Object>> list) {
        this.activity = activity;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == view) {
            holder = new ViewHolder();
            view = LayoutInflater.from(activity).inflate(R.layout.item_list_view_user, parent, false);
            holder.iconView = (ImageView) view.findViewById(R.id.item_image_view_titile);
            holder.titleText = (TextView) view.findViewById(R.id.item_text_view_title);
            holder.iconMore = (ImageView) view.findViewById(R.id.item_image_view_more);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.iconView.setImageResource((int) list.get(position).get(FlagHelper.ICON_IMAGE));
        holder.titleText.setText((String) list.get(position).get(FlagHelper.TEXT_TITLE));
        holder.iconMore.setImageResource((int) list.get(position).get(FlagHelper.ICON_MORE));
        return view;
    }

    class ViewHolder {
        public ImageView iconView;
        public TextView titleText;
        public ImageView iconMore;
    }
}
